//
//  UITableview+Extension.swift
//
//  Created by 谢强 on 15/03/2018.
//  Copyright © 2018 谢强. All rights reserved.
//

import UIKit

// MARK: - 入口
extension UITableView {
    
    private struct AssociatedKeys {
        /// 拖拽排序
        static var sortableControllerKey: UInt8 = 0
    }
    
    /// 拖拽排序
    public var sortable: SortableController {
        if let sortableController = objc_getAssociatedObject(self, &AssociatedKeys.sortableControllerKey) as? SortableController {
            return sortableController;
        } else {
            let sortableController = SortableController(tableview: self);
            objc_setAssociatedObject(self, &AssociatedKeys.sortableControllerKey, sortableController, .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
            return sortableController;
        }
    }
}
